import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  // 此处添加登录界面的路由
  {
    path: "/login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: () => import("../views/Home.vue"),
    children: [
      {
        path: "/home",
        redirect: "/home/main",
      },
      {
        path: "/home/main",
        component: () => import("../views/Home/Main.vue"),
        children: [
          {
            path: "/home/main",
            redirect: "/home/main/recommend",
          },
          {
            path: "/home/main/recommend",
            component: () => import("../views/Home/Main/Recommend.vue"),
          },
          {
            path: "/home/main/tell",
            component: () => import("../views/Home/Main/Tell.vue"),
          },
          {
            path: "/home/main/slowtell",
            component: () => import("../views/Home/Main/SlowTell.vue"),
          },
          {
            path: "/home/main/loudvoice",
            component: () => import("../views/Home/Main/LoudVoice.vue"),
          },
        ],
      },
      {
        path: "/home/speak",
        component: () => import("../views/Home/Speak.vue"),
      },
      {
        path: "/home/find",
        component: () => import("../views/Home/Find.vue"),
      },

      {
        path: "/home/mine",
        component: () => import("../views/Home/Mine.vue"),
      },
    ],
  },
  {
    path: "/detail/:id",
    component: () => import("../views/Detail.vue"),
    props: true,
  },
  {
    path: "/vip",
    component: () => import("../views/Vip.vue"),
  },
  {
    path: "/sign",
    component: () => import("../views/Sign.vue"),
    beforeEnter(to, from, next) {
      if (localStorage.getItem("user")) {
        next();
      } else {
        next("/login");
      }
    },
  },
  {
    path: "/compile",
    component: () => import("../views/Compile.vue"),
  },
  {
    path: "/resource",
    component: () => import("../views/Resource.vue"),
  },
  {
    path: "/service",
    component: () => import("../views/Service.vue"),
  },
  {
    path: "/video",
    component: () => import("../views/Video.vue"),
  },
  {
    path: "/comment",
    component: () => import("../views/Comment.vue"),
  },
  {
    path: "/activity",
    component: () => import("../views/Activity.vue"),
  },
  {
    path: "/search",
    component: () => import("../views/Search.vue"),
  },
  {
    path: "/information",
    component: () => import("../views/Information.vue"),
    beforeEnter(to, from, next) {
      if (localStorage.getItem("user")) {
        next();
      } else {
        next("/login");
      }
    },
  },
  {
    path: "/shopping",
    component: () => import("../views/Shopping.vue"),
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("../views/Nofound.vue"),
  },
  // 线下书店
  {
    path: "/offlinebookstore",
    component: () => import("../views/OfflineBookstore.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

export default router;
